/**
 * 
 */
package com.testapp;

import com.eteks.parser.CalculatorParser;
import com.eteks.parser.CompilationException;

/**
 * @author Pratik
 * Created on : 26-Jun-2011, 4:27:27 PM
 */
public class Utils {
	public static String calculateLHS(String lhs) {
		StringBuffer sb = new StringBuffer();
		
		if(lhs != null) {
			try {
				double result = getCalculationResult(lhs);
				sb.append(result);
			} catch (Throwable th) {
				if(th instanceof CompilationException) {
					sb.append(((CompilationException)th).getError());
				} else {
					sb.append("Unparsable Parameters.");
				}
				sb.append(".");
			}
		}
		
		return sb.toString();
	}
	
	private static double getCalculationResult(String lhs) throws CompilationException {
		CalculatorParser cp = new CalculatorParser();
		return cp.computeExpression(lhs);
	}
}
